package com.immunology.servlets;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.immunology.model.Complaint;
import com.immunology.model.ComplaintType;
import com.immunology.model.MappingPages;
import com.immunology.service.ComplaintService;
import com.immunology.service.ComplaintTypeService;

public class EditComplaintServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public EditComplaintServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		getServletContext().getRequestDispatcher(
				MappingPages.SHOW_COMPLAINT_JSP).forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String complaintName = request.getParameter("complaintName");
		@SuppressWarnings("unchecked")
		Enumeration<String> enumeration = request.getParameterNames();
		int complaintId = Integer.parseInt(enumeration.nextElement());
		ComplaintService complaintService = ComplaintService.getInstance();
		Complaint complaint = complaintService.getComplaintById(complaintId);
		complaint.setName(complaintName);
		complaintService.update(complaintId,complaint);
		getServletContext()
				.getRequestDispatcher(MappingPages.SHOW_COMPLAINT_JSP).forward(
						request, response);
	}

}
